<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; char_set=utf-8" >
    <meta name="viewport" content="width=device-width,initial-scale=1, maximum-scale=1,user-scalable=no">
    <meta charset="utf-8">
    <title>熊猫</title>
    <link rel="stylesheet" href="static/css/submit.css">
</head>
<body>
    <div class="container">
        <div class="panda">
            <div class="ear left"></div>
            <div class="ear right"></div>
            <div class="face">
                <div class="eye-shadow left"></div>
                <div class="eye-white left">
                    <div class="eye-ball"></div>
                </div>
                <div class="eye-shadow right"></div>
                <div class="eye-white right">
                    <div class="eye-ball"></div>
                </div>
            <div class="nose"></div>
            <div class="mouth"></div>
            </div>
            <div class="body"></div>
            <div class="foot left">
                <div class="sole"></div>
            </div>
            <div class="foot right">
                <div class="sole"></div>
            </div>
        </div>
        <form class="layui-form" action="">
        <div class="login-box ">
            <div class="hand left"></div>
            <div class="hand right"></div>
            <h1>添+1</h1>
            <div class="box">

                <input type="text" name="username" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                <label>请输入用户名</label>

            </div>
            <div class="box">
                <input type="password" name="userpass" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                <label>请输入密码</label>

            </div>


                    <button class="layui-btn" type="button" lay-submit lay-filter="formDemo">登录</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>

        </div>
        </form>
    </div>
    <script src="static/lib/jquery-3.6.0.min.js"></script>
    <script>
        $('#userpass').focusin(function (){
            $('.login-box').addClass('up');
        }).focusout(function (){
            $('.login-box').removeClass('up');
        })
        $(document).on('mousemove',function (e){
            let dw=$(document).width() / 10;
            let dh=$(document).height() / 18;
            let x=e.pageX / dw;
            let y=e.pageY / dh;
            $('.eye-ball').css({
                left:x,
                top:y
            })
        })
    </script>
    <script src="static/lib/layui-v2.6.8/layui/layui.js"></script>
    <script>
        //Demo
        var $ = layui.$;
        layui.use('form', function(){
            console.log(1)
            var form = layui.form;
            form.on('submit(formDemo)', function(data){
                var f = data.field;
                console.log(f)
                if (f.username==null){
                    layer.msg("请输入用户名")
                }
                if (f.userpass==null){
                    layer.msg("请输入密码")
                }
                $.ajax({
                    url:"./user/check",//登录
                    data:{
                        username:f.username,
                        userpass:f.userpass
                    },success(res){
                        console.log(res)
                        if (res==0){
                            layer.open({
                                type:1,
                                title:"请更改初始密码后重试",
                                btn:['确定','取消'],
                                yes:function (){
                                    console.log("tijiao");
                                    layer.prompt(function(value, index, elem){
                                        console.log(data)
                                        $.ajax({
                                            url: './user/editpass',
                                            data:{
                                                username:f.username,
                                                userpass: value
                                            },
                                            success:function (res) {
                                                console.log(res+"-----")
                                                if (res==1){
                                                    $.ajax({
                                                        url:'./staff/editstate',
                                                        data:{
                                                            username:f.username
                                                        },
                                                        success:function (res) {
                                                            if (res==1) {
                                                                alert("密码修改成功");
                                                                location.replace(location)
                                                            }else {
                                                                alert("密码更改失败")

                                                            }

                                                        }
                                                    })
                                                }

                                            }
                                        })
                                    });

                                },
                                btn2:function (){
                                    console.log("quxiao")
                                }
                            })
                        }else if (res==1){
                            $(location).attr("href","pages/t")
                        }else if (res==2){
                            layer.msg("员工已离职，无法登陆")
                        }else if (res==3){
                            layer.msg("密码错误")
                        }else if (res==4){
                            layer.msg("用户名或密码错误")
                        }else if (res==5){
                            layer.msg("用户名或密码错误")
                        }
                        else  {
                            layer.msg("用户名或密码错误")
                        }
                    }
                });

                // setTimeout(function(){//设置定时器
                //     parent.location.reload(true);//刷新父级页面
                //     var index = parent.layer.getFrameIndex(window.name);
                //     parent.layer.close(index);
                // },1000);
            });
        });
    </script>





</body>
</html>